home *** CD-ROM | disk | FTP | other *** search
/ LOGIC Apps / Logic-APPLE_II_APPS.iso / mac / LOGIC Apple II 5.25" Library - ProDOS / PRO081.dsk / MISCELLANEOUS / MISC.10.GETCHAR.txt < prev    next >
Text File  |  2012-02-16  |  6KB  |  108 lines

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. Apple II Miscellaneous
  8. #10:    80-Column GetChar Routine
  9.  
  10. Revised by:    Pete McDonald                                    November 1988
  11. Written by:    Cameron Birse                                    December 1986
  12.  
  13. This Technical Note presents an 80-column GetChar routine.
  14. _____________________________________________________________________________
  15.  
  16. The following is an example of how to display a string on the 80-column 
  17. screen, reposition the cursor at the beginning of the string, and use the 
  18. right arrow to get characters which are already there or accept new characters 
  19. in their place.  The routine is a simple BASIC program which displays the 
  20. string and repositions the cursor before getting incoming characters.  If the 
  21. character input is a right arrow, the program calls the assembly language 
  22. routine to get the character from screen memory at the current cursor 
  23. location.
  24.  
  25. 10  PRINT  CHR$ (4);"bload getchar.0": REM  first install assembly routine
  26. 20  B$ = "hello"
  27. 30  PRINT  CHR$ (4);"pr#3"
  28. 40  PRINT B$;:B$ = ""
  29. 50  A =  PEEK (1403): REM  get horiz location
  30. 60  A = A - 5: REM  move cursor to beginning of string
  31. 70  POKE 1403,A
  32. 80  GET A$: REM  get a character
  33. 90  IF A$ =  CHR$ (21) THEN  GOSUB 130: REM   if char is forward arrow,
  34.     handle with assembly routine (GETCHAR)
  35. 100  IF A$ =  CHR$ (27) THEN 170: REM   if esc key then we're done
  36. 110  PRINT A$;:B$ = B$ + A$
  37. 120  GOTO 80
  38. 130  CALL 768: REM   GETCHAR
  39. 140  A =  PEEK (6)
  40. 150  A$ =  CHR$ (A)
  41. 160  RETURN 
  42. 170  PRINT : PRINT : PRINT B$: REM  and we're done
  43.  
  44. An assembled listing of the assembly language GetChar routine follows on the 
  45. next page.
  46.  
  47. SOURCE   FILE #01 =>GETCHAR
  48. ----- NEXT OBJECT FILE NAME IS GETCHAR.0                     
  49. 0300:        0300    1           ORG   $300           
  50. 0300:        C01F    2 RD80VID   EQU   $C01F         ;80 COLUMN STATE
  51. 0300:        C054    3 TXTPAGE1  EQU   $C054         ;TURN OFF PAGE 2 (READ)
  52. 0300:        C055    4 TXTPAGE2  EQU   $C055         ;TURN ON PAGE 2 (READ)
  53. 0300:        C000    5 CLR80COL  EQU   $C000         ;TURN OFF 80 STORE (WRITE)
  54. 0300:        C001    6 SET80COL  EQU   $C001         ;TURN ON 80 STORE (WRITE)
  55. 0300:        0028    7 BASL      EQU   $28           ;BASE ADDRESS OF SCREEN LOCATION
  56. 0300:        0029    8 BASH      EQU   $29
  57. 0300:        057B    9 OURCH     EQU   $57B          ;80 COLUMNS HORIZ. POSITION
  58. 0300:        05FB   10 OURCV     equ   $5fb          ;80 col vertical pos
  59. 0300:        0006   11 char      equ   6             ;place to hand character back to basic
  60. 0300:               12 *
  61. 0300:               13 *************************************************************
  62. 0300:               14 *   GETCHAR - This routine gets an ascii character from the *
  63. 0300:               15 *   80 column display memory of the Apple IIe. It assumes   *
  64. 0300:               16 *   that main memory is switched in and that the base addrs *
  65. 0300:               17 *   of the line has already been calculated and resides     *
  66. 0300:               18 *   in BASL and BASH. It is meant to be called from BASIC   *
  67. 0300:               19 *   as follows:                                             *
  68. 0300:               20 *                     CALL 768                              *
  69. 0300:               21 *                     A = PEEK (6)                          *
  70. 0300:               22 *                     A$ = CHR$(A)                          *
  71. 0300:               23 *   As you can see, the character is returned in location   *
  72. 0300:               24 *   $6 in zero page. This routine is offered as an example. *
  73. 0300:               25 *   No guaranties are made regarding its fitness for any    *
  74. 0300:               26 *   purpose.           By Cameron Birse 6/10/86             *
  75. 0300:               27 *************************************************************
  76. 0300:               28 *
  77. 0300:        0300   29 getchr    equ   *             ;get the char at the current cursor loc.
  78. 0300:A9 01          30           lda   #$01          ;mask for horiz test
  79. 0302:2C 7B 05       31           bit   OURCH         ;are we in main or aux mem?
  80. 0305:D0 17   031E   32           bne   main          ;if bit 0 of OURCH is set, then main mem
  81. 0307:        0307   33 aux       equ   *
  82. 0307:AD 7B 05       34           lda   OURCH         ;get horiz pos.
  83. 030A:18             35           clc                 ;clear the carry for divide
  84. 030B:6A             36           ror   a             ;divide by two
  85. 030C:A8             37           tay                 ;put the result in y
  86. 030D:8D 01 C0       38           sta   SET80COL      ;turn on 80 store
  87. 0310:AD 55 C0       39           lda   TXTPAGE2      ;flip to aux text page
  88. 0313:B1 28          40           lda   (basl),y      ;get the character
  89. 0315:85 06          41           sta   char
  90. 0317:AE 54 C0       42           ldx   TXTPAGE1      ;turn off aux text page
  91. 031A:8D 00 C0       43           sta   CLR80COL      ;turn off 80 store
  92. 031D:60             44           rts
  93. 031E:        031E   45 main      equ   *
  94. 031E:AD 7B 05       46           lda   OURCH         ;get horiz pos.
  95. 0321:18             47           clc                 ;clear the carry for divide
  96. 0322:6A             48           ror   a             ;divide by two
  97. 0323:A8             49           tay                 ;put the result in y
  98. 0324:B1 28          50           lda   (basl),y      ;get the character
  99. 0326:85 06          51           sta   char
  100. 0328:60             52           rts
  101.  
  102.  
  103. Further Reference
  104. o    Apple IIGS Firmware Reference
  105. o    Apple IIe Technical Reference Manual
  106. o    Apple IIc Technical Reference Manual
  107.  
  108.